package email;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

/* This class displays a simple dialog instructing the user
   that messages are being downloaded. */
public class DownloadingDialog extends JFrame {
	
	JLabel contentLabel = null;

    // Constructor for dialog.
    public DownloadingDialog(Frame parent) {
    	// Set dialog size.
    	setSize(500,150);
        // Set dialog title.
        setTitle("Please Wait");
        
        // Instruct window not to close when the "X" is clicked.
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(new GridLayout(4,4));
        // Put a message with a nice border in this dialog.
        JLabel label = new JLabel();
        JButton cancel = new JButton("Cancel");
        contentLabel = label;
        label.setText("Downloading message " + EmailClient2.messageIndex + " of " + EmailClient2.messageLength);
        getContentPane().add(label);
        getContentPane().add(cancel);
        cancel.addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
				
			}
        	
        });
        
        setResizable(false);
        // Center dialog over application.
        setLocationRelativeTo(parent);
    }
    
    public void refreshLabel(){
    	if(contentLabel != null){
        	contentLabel.setText("Downloading message " + EmailClient2.messageIndex + " of " + EmailClient2.messageLength);
    	}
    }

}